<?php
require('util/DBUtil.php');
$serv = new swoole_server("0.0.0.0", 9501);

//设置异步任务的工作进程数量
$serv->set(array('task_worker_num' => 4));

$serv->on('receive', function ($serv, $fd, $reactor_id, $data) {
   	if(DBUtil::saveToDB(json_decode($data))){
		$sendEmail = $serv->task($data);
		$sendGift= $serv->task($data);
		$serv->send($fd,'success');
	
	} 
});

$serv->on('task',function($serv,$task_id,$from_id,$data){
	echo '执行任务ID是'.$task_id.PHP_EOL;
	return 1;
	
});
$serv->on('finish',function($serv,$task_id,$data){
	 echo "执行结束[$task_id] Finish: $data".PHP_EOL;	
});

$serv->start();
